package cn.kgc.vueair.controller;

import cn.kgc.vueair.pojo.Quality;
import cn.kgc.vueair.pojo.ResultEntity;
import cn.kgc.vueair.service.QualityService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class QualityController {
    @Resource
    QualityService qualityService;
    @RequestMapping("/selectQuality")
    public ResultEntity<PageInfo<Quality>> selectquality(@RequestParam(value = "districtid",required = false,defaultValue = "0")Integer districtid,
                                                         @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
                                                         @RequestParam(value = "pageSize",required = false,defaultValue = "6")Integer pageSize){
        PageInfo<Quality> qualityPageInfo=qualityService.select(pageNum,pageSize,districtid);
        return ResultEntity.successWithoutData(qualityPageInfo);
    }
    @RequestMapping("/saveQuality")
    public ResultEntity<String> saveQuality(@RequestBody Quality quality){
        try {


        Integer integer=0;
        if (quality.getId()==null){
            integer=qualityService.add(quality);

        }else {
            integer=qualityService.update(quality);
        }
        return ResultEntity.successWithoutData(integer+"");
        }catch (Exception ex){
            return ResultEntity.failed(ex.getMessage());
        }

    }
    @RequestMapping("/getQualityById")
    public ResultEntity<Quality> getQualityById(Integer id){
        Quality quality=qualityService.selectById(id);
        return ResultEntity.successWithoutData(quality);
    }
    @RequestMapping("/delQualityById")
    public ResultEntity<String> delQualityById(Integer id){
        try {
            Integer integer=qualityService.delete(id);
            return ResultEntity.successWithoutData(integer+"");
        }catch (Exception ex){
            return ResultEntity.failed(ex.getMessage());
        }
    }
}
